-- a script that announces your ip address on the soundcard; for use with headless systems
-- specifically on open-wrt based routers with usbsound
-- by Chad Mounteny, June 2009
-- requires that 'madplay' be installed
-- edit so correct interface is polled (probably eth0.1 for openwrt, eth0 for everything else)
-- expects sounds in ./soundb

interface = "eth0"

function play(name)
    if name  == "." then
        name = "dot"
    end
    os.execute(string.format("madplay  -Q sound/%s.mp3",name))
end

cmd_output = io.popen(string.format("ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'",interface))
ip = string.gsub(cmd_output:read("*a"),"^%s*(.-)%s*$","%1")
for i=1,string.len(ip) do
    play (string.sub(ip,i,i))
end

